<template>
  <el-dropdown trigger="click" class="international" @command="handleSetLanguage">
    <span class="el-dropdown-link yt-top-lg">{{ $t('language') }}<i class="el-icon-arrow-down el-icon--right"></i></span>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="tc">{{$t('components.langSelect.tc')}}</el-dropdown-item>  <!--繁体中文-->
      <el-dropdown-item command="ch">{{$t('components.langSelect.ch')}}</el-dropdown-item>  <!--简体中文-->
      <el-dropdown-item command="us">{{$t('components.langSelect.us')}}</el-dropdown-item>  <!--美式英文-->
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
  // import { getLoginName, getLoginPwd } from '@/utils/auth';
  import { changeLanguage } from '@/api/e-formula/user/index';

  export default {
    computed: {
      languageA() {
        return this.$store.getters.language;
      }
    },
    data() {
      return {
      };
    },
    methods: {
      handleSetLanguage(lang) {
        this.$i18n.locale = lang
        this.$store.dispatch('setLanguage', lang)
        this.$store.dispatch('setTitle', this.$t('title'))

        changeLanguage(lang).then(() => {
          location.reload();


          document.title = this.$store.state.app.title
          // const loginName = getLoginName();
          // const password = getLoginPwd();
          // this.$store.dispatch('LogOut').then(() => {
          //   this.$store
          //     .dispatch('LoginByUsername', {
          //       username: loginName,
          //       password
          //     })
          //     .then(() => {
          //       location.reload();
          //     });
        });
      }
    }
  };
</script>

<style scoped>
  .international-icon {
    font-size: 20px;
    cursor: pointer;
    vertical-align: -5px !important;
  }
</style>


